package UIFree.controls
{
	import UIFree.controls.uif_hscrollArea;
	import UIFree.uif_component;
	
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.geom.Rectangle;

	public class uif_tabs extends uif_hscrollArea {
		public static var TOPSPACE: int = 5;
		public static var NOACTIVEALPHA: Number = 1;
		
		public function uif_tabs(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:String='') {
			super(parent, ax, ay, awidth, aheight, styleClass, aheight);
		}
		
		override protected function createElement(c_func: Function, inner: Rectangle, i: int): uif_component {
			inner.y += TOPSPACE;
			inner.height += 2;
			var control: uif_component = c_func(_scroll, inner, i);
			control.alpha = NOACTIVEALPHA;
			return control;
		}
		
		protected function unselectFX(item: uif_component): void {
			var inner: Rectangle = scrollArea.getInner();
			item.fx('y', item.y, inner.y + TOPSPACE).start();
			item.alphaFX(NOACTIVEALPHA);
			if (style['unselect']) item.styleClass = style['unselect'];
		}
		
		protected function selectFX(item: uif_component): void {
			var inner: Rectangle = scrollArea.getInner();
			item.fx('y', inner.y + TOPSPACE, inner.y).start();
			item.alphaFX(1);
			if (style['select']) item.styleClass = style['select'];
		}
		
		override public function set selectIndex(a_index: int): void {
			if ((!disable) && (a_index != selectIndex) && (items.length > 0)) {
				
				for (var i:int; i<items.length - 1; i++)
					scrollArea.setChildIndex(items[i].control, i);
					
				scrollArea.setChildIndex(items[a_index].control, items.length - 1);
				
				if (TOPSPACE) {
					var ctrl: uif_tabItem;
					if (selectIndex > -1) unselectFX(items[selectIndex].control);
					selectFX(items[a_index].control);
				}
				
				super.selectIndex = a_index;
				//this.dispatchEvent(new Event(Event.SELECT));
			}
		}
	}
}